package com.dhcc.core.modules.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.CacheClear;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.core.modules.system.cache.group.IGroupCache;
import com.dhcc.core.modules.system.entity.GroupMember;
import com.dhcc.core.modules.system.service.IGroupMemberService;


/**
 * 群组成员
 * 
 * @ClassName: GroupMemberController
 * @Description: TODO
 * @author lifan
 * @date 2018-08-21 15:30:14
 */
@Controller
@RequestMapping("${sys.backendPath}/member")
public class GroupMemberController extends BaseController {

    @Autowired
    private IGroupMemberService groupMemberService;
	

    /**
     * 获取群组成员列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<GroupMember> page = new PageFactory<GroupMember>().defaultPage();
        List<GroupMember> result = this.groupMemberService.list(page,params);
        page.setRecords((List<GroupMember>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增群组成员
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @BussinessLog(value = "新增群组成员")
    @CacheClear(IGroupCache.CACHE_NAME)
    public Object add(@RequestParam String user_id) {
    	System.out.println(user_id);
        if (CommonUtil.isOneEmpty(user_id)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.groupMemberService.insertGroupMember(user_id);
        return R.ok();
    }

    /**
     * 删除群组成员
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @BussinessLog(value = "删除群组成员")
    @CacheClear(IGroupCache.CACHE_NAME)
    public Object delete(@RequestParam Long groupMemberId) {
        this.groupMemberService.deleteById(groupMemberId);
        return R.ok();
    }

	
}
